<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  medias
 */

class m_medias_actions_block_MceObjectDetailAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$object = $this->getDocumentProvider()->getByUniqueId($this->getRequestParameter("docId"), $this->getRequestParameter("docLang"));

        $urls = $this->getUrlsFromObjId($this->getRequestParameter("docId"),  $this->getRequestParameter("rootFolder"));

        $this->addToModel("urls", $urls);
        $this->addToModel("object", $object);

		$this->setView("success");
	}	
    
    private function getUrlsFromObjId($id, $module)
    {
        $documentProvider = f_document_Provider::getInstance();
        $dbProvider = f_database_Provider::getInstance();

        $rlManager = f_relation_Manager::getInstance();

        $parent = $rlManager->getUniqueParent($id);

        if($parent != null)
        {

            $res = $dbProvider  ->setQuery('SELECT * FROM `m_website__page` WHERE `content` REGEXP \'module="'.$module.'".*(contentId="'.$parent->getUniqueId().'"|folderId="'.$parent->getUniqueId().'"|folder="'.$parent->getUniqueId().'")\'')
                                ->execute()
                                ->getQueryResults();

            return $res;
        }

        return null;
    }
}